import api from './axios';
import store from '@/store/index'

function getdeanId() {
  return store.state.login.deanId || sessionStorage.getItem("deanId")
};

function getUserid() {
  let user_info = sessionStorage.getItem("userInfo");
  return store.state.login.user.id || (user_info ? JSON.parse(user_info).id : "");
};



const deanId = getdeanId();

export default {
  //登录
  loginByPassword(data) {
    return api.post("/auth", JSON.stringify(data));
  },
  //   ###床位管理###
  // 床位信息(床位管理)
  bloodSugarBed(data) {
    data.deanId = getdeanId();
    return api.get(`/bloodSugarBed/getBedInfo?deanId=${data.deanId}&departmentId=${data.departmentId}&current=${data.current}`);
  },
  // 添加床位 (床位管理)
  addBedInfo(data) {
    data.deanId = getdeanId();
    return api.post("/bloodSugarBed/addBedInfo", JSON.stringify(data));
  },
  // 删除床位(床位管理)
  deleteBedInfo(data) {
    return api.get(`/bloodSugarBed/deleteBedInfo/${data.id}`);
  },
  //查询科室
  getDepartment(data) {
    data.deanId = getdeanId();
    data.currentLoginUserId = getUserid();
    return api.get(`/bloodSugarDepartment/getDepartmentByPerId/${data.perId}/${data.currentLoginUserId}/${data.deanId}`);
  },

  /**
   * 
   * @param {*首页开始} data 
   * @returns 
   */
  // 首页所有床位,患者信息
  getIndexUserInfo(data) {
    data.deanId = getdeanId();
    data.currentLoginUserId = getUserid();
    return api.post("/bloodSugarPatientInfo/getIndexUserInfo", JSON.stringify(data));
  },
  // 患者详情
  getpatientDetails(data) {
    return api.get(`/bloodSugarPatientInfo/getIndexUserBaseInfoById/id/${data.id}`);
  },
  // 患者详情,编辑控糖目标 
  updatePatient(data) {
    data.deanId = getdeanId();
    return api.post("/bloodSugarPatientInfo/updatePatientTargetValues", JSON.stringify(data));
  },
  // 更新患者控糖目标
  patientTarget(data) {
    data.deanId = getdeanId();
    return api.post("/bloodSugarPatientInfo/updatePatientTarget", JSON.stringify(data));
  },
  // 添加患者 
  addPatientInfo(data) {
    data.deanId = getdeanId();
    data.currentLoginUserId = getUserid();
    return api.post("/bloodSugarPatientInfo/addPatientInfo", JSON.stringify(data));
  },
  // 患者详情 -->基础信息
  getInfoDetail(data) {
    return api.get(`/bloodSugarPatientInfo/getIndexUserBaseInfoDetail/${data.id}`);
  },
  // 基础信息,修改完成提交 
  updatePatientInfo(data) {
    data.deanId = getdeanId();
    data.currentLoginUserId = getUserid();
    return api.post("/bloodSugarPatientInfo/updatePatientInfo", JSON.stringify(data));
  },
  // 添加患者使用床位信息 
  getAllBedNum(data) {
    data.deanId = getdeanId();
    data.currentLoginUserId = getUserid();
    return api.get(`/bloodSugarPatientInfo/getAllBedNum?deanId=${data.deanId}&departmentId=${data.departmentId}&current=${data.current}&size=${data.size}`);
  },
  // 关注患者,取消关注患者 
  attentionUser(data) {
    return api.get(`/bloodSugarPatientInfo/attentionUser?doctorId=${data.doctorId}&userId=${data.userId}`);
  },
  // 血糖测量数据 
  getallbloodsugar(data) {
    data.deanId = getdeanId();
    return api.get(`/bloodSugarPatientInfo/getIndexUserBloodGlucoseInfo?deanId=${data.deanId}&id=${data.id}&current=${data.current}&startTime=${data.startTime}&endTime=${data.endTime}`);
  },
  // 添加血糖记录
  addGlucoseRecord(data) {
    data.deanId = getdeanId();
    return api.get(`/bloodSugarPatientInfo/addGlucoseRecord?deanId=${data.deanId}&userId=${data.userId}&attr=${data.attr}&sugarValue=${data.sugarValue}&examTime=${data.examTime}`);
  },
  // 
  getDetailbloodsugar(data) {
    data.deanId = getdeanId();
    return api.get(`/bloodSugarPatientInfo/getIndexUserBloodGlucoseDetail?deanId=${data.deanId}&time=${data.time}&attr=${data.attr}&id=${data.id}`);
  },
  // 患者出入院记录  
  hospitalRecords(data) {
    data.deanId = getdeanId();
    return api.get(`/bloodSugarPatientInfo/getIndexUserOutInHospitalRecord?deanId=${data.deanId}&hospitalNum=${data.hospitalNum}&current=${data.current}`);
  },
  // 患者出院 
  outHospital(data) {
    data.deanId = getdeanId();
    data.userId = getUserid();
    return api.get(`/bloodSugarPatientInfo/updatePatientOutHospital?id=${data.id}`);
  },


  /** 
   * @质量管理
   */
  // 试纸批次号信息
  getArticleTryInfo(data) {
    data.deanId = getdeanId();
    return api.get(`/bloodSugarArticleTry/getArticleTryInfo?deanId=${data.deanId}&departmentId=${data.departmentId}&startTime=${data.startTime}&endTime=${data.endTime}&current=${data.current}`);
  },
  // 添加试纸批号 
  addArticleTry(data) {
    data.deanId = getdeanId();
    data.userId = getUserid();
    return api.post("/bloodSugarArticleTry/addArticleTry", JSON.stringify(data));
  },
  // 质控批号 
  getQualityControl(data) {
    data.deanId = getdeanId();
    return api.get(`/bloodSugarQualityControl/getQualityControl?deanId=${data.deanId}&departmentId=${data.departmentId}&current=${data.current}`);
  },
  // 添加质控批号信息
  addQualityControl(data) {
    data.deanId = getdeanId();
    data.userId = getUserid();
    return api.post("/bloodSugarQualityControl/addQualityControl", JSON.stringify(data));
  },
  // 所有的质控检测记录
  getCheckRecord(data) {
    data.deanId = getdeanId();
    return api.get(`/bloodSugarQualityRecords/getQualityControl?deanId=${data.deanId}&departmentId=${data.departmentId}&current=${data.current}&startTime=${data.startTime}&endTime=${data.endTime}`);
  },
  /**
   * 
   * @添加质控检测记录
   */

  // 查询科室下的试纸批次号信息,下拉框使用
  getAllArticleTryInfo(data) {
    data.deanId = getdeanId();
    return api.get(`/bloodSugarArticleTry/getAllArticleTryInfo?deanId=${data.deanId}&departmentId=${data.departmentId}`);
  },
  // 查询科室下的质控批号信息 下拉框使用
  getAllQualityControl(data) {
    data.deanId = getdeanId();
    return api.get(`/bloodSugarQualityControl/getAllQualityControl?deanId=${data.deanId}&departmentId=${data.departmentId}`);
  },
  // 查询科室下的所有设备,下拉框使用
  getEquipmentInfo(data) {
    data.deanId = getdeanId();
    return api.get(`/bloodSugarEquipment/getAllEquipmentInfo?deanId=${data.deanId}&departmentId=${data.departmentId}`);
  },
  // 添加质控检测记录
  addQualityRecords(data) {
    data.deanId = getdeanId();
    data.userId = getUserid();
    return api.post("/bloodSugarQualityRecords/addQualityRecords", JSON.stringify(data));
  },
  /**
   * 
   * @数据管理
   */
  //查看所有数据管理信息
  getAllDataInfo(data) {
    data.deanId = getdeanId();
    data.userId = getUserid();
    return api.post("/bloodSugarPatientInfo/getAllDataInfo", JSON.stringify(data));
  },
  //数据管理患者基本信息数据 
  getDataUserInfo(data) {
    return api.get(`/bloodSugarPatientInfo/getDataUserBaseInfoById/id/${data.id}`);
  },
  //查询数据管理 折线图信息
  getLineChartInfo(data) {
    return api.get(`/bloodSugarPatientInfo/getDataUserLineChartInfo?id=${data.id}`);
  },
  /**
   * @条形码管理 
   */
  // 查询所有条形码信息
  getAllBarCode(data) {
    data.deanId = getdeanId();
    return api.get(`/bloodSugarEquipment/getAllBarcodeInfo?deanId=${data.deanId}&departmentId=${data.departmentId}&current=${data.current}&size=${data.size}`);
  },
  /**
   * zhao
   * @设备管理
   */
  // 查询所有设备
  getAllEquipmentInfo(data) {
    data.deanId = getdeanId();
    return api.post("/bloodSugarEquipment/getEquipmentInfo", JSON.stringify(data))
  },
  // 添加设备
  addEquipmentInfo(data) {
    data.deanId = getdeanId();
    return api.post("/bloodSugarEquipment/addEquipmentInfo", JSON.stringify(data))
  },
  //修改设备
  updateEquipmentInfo(data) {
    data.deanId = getdeanId();
    return api.post("/bloodSugarEquipment/updateEquipmentInfo", JSON.stringify(data))
  },
  // 删除设备
  deleteEquipment(data) {
    data.deanId = getdeanId();
    return api.get(`/bloodSugarEquipment/deleteEquipmentInfo/${data.id}`);
  },


  /**
   * zhao
   * @权限管理
   */
  // 查询所有角色权限  用于添加修改页面的下拉框
  getAllRoleInfo(data) {
    data.deanId = getdeanId();
    return api.post("/bloodSugarRole/getAllRoleInfo", JSON.stringify(data))
  },
  //pc查询所有角色 角色管理添加修改角色信息下拉框使用
  getRoleInfo(data) {
    data.deanId = getdeanId();
    return api.post("/bloodSugarRole/getRoleInfo", JSON.stringify(data))
  },
  // 添加角色权限
  addRole(data) {
    data.deanId = getdeanId();
    return api.post("/bloodSugarRole/addRole", JSON.stringify(data))
  },
  //修改角色权限
  updateRole(data) {
    data.deanId = getdeanId();
    // data.roleId=getRoleid()//获取缓存的角色管理的userid
    return api.post("/bloodSugarRole/updateRole", JSON.stringify(data))
  },
  // 删除角色权限
  deleteRole(data) {
    data.deanId = getdeanId();
    return api.get(`/bloodSugarRole/deleteRole`);
  },
  // 获取角色权限
  getRole(data) {
    data.deanId = getdeanId();
    return api.get(`/bloodSugarRole/getRole?deanId=${data.deanId}&userId=${data.userId}`);
  },
  //添加时获取权限列表
  getRoleAdd(data) {
    data.deanId = getdeanId();
    return api.get(`/bloodSugarRole/getAllPermissionToAdd?deanId=${data.deanId}`)
  },
  //修改用户启用状态
  updateUserStatus(data) {
    // data.deanId = getdeanId();
    return api.get(`/bloodSugarRole/updateUserRoleStatus/${data.userId}/${data.isDisable}`);
  },
  /**
   * zhao
   * @科室管理
   */
  //查询科室
  getDepartmentAll(data) {
    data.deanId = getdeanId();
    return api.get(`/bloodSugarDepartment/getDepartment?deanId=${data.deanId}&current=${data.current}&departmentName=${data.departmentName}`);
  },

  // 添加科室
  addDepartment(data) {
    data.deanId = getdeanId();
    return api.post("/bloodSugarDepartment/addDepartment", JSON.stringify(data))
  },
  //修改科室
  updateDepartment(data) {
    data.deanId = getdeanId();
    return api.get(`/bloodSugarDepartment/updateDepartment/${data.departmentName}/${data.id}`);
  },
  // 删除科室
  deleteDepartment(data) {
    data.deanId = getdeanId();
    return api.get(`/bloodSugarDepartment/deleteDepartment/${data.id}`);
  },

  // 查询科室下的试纸批次号信息,下拉框使用
  getAllArticleTryInfo(data) {
    data.deanId = getdeanId();
    return api.get(`/bloodSugarArticleTry/getAllArticleTryInfo?deanId=${data.deanId}&departmentId=${data.departmentId}`);
  },
  // 查询科室下的质控批号信息 下拉框使用
  getAllQualityControl(data) {
    data.deanId = getdeanId();
    return api.get(`/bloodSugarQualityControl/getAllQualityControl?deanId=${data.deanId}&departmentId=${data.departmentId}`);
  },
  // 查询科室下的所有设备,下拉框使用
  getEquipmentInfo(data) {
    data.deanId = getdeanId();
    return api.get(`/bloodSugarEquipment/getAllEquipmentInfo?deanId=${data.deanId}&departmentId=${data.departmentId}`);
  },
  // 添加质控检测记录
  addQualityRecords(data) {
    data.deanId = getdeanId();
    data.userId = getUserid();
    return api.post("/bloodSugarQualityRecords/addQualityRecords", JSON.stringify(data));
  },
  /**
   * 
   * @数据管理
   */
  //查看所有数据管理信息
  getAllDataInfo(data) {
    data.deanId = getdeanId();
    data.userId = getUserid();
    return api.post("/bloodSugarPatientInfo/getAllDataInfo", JSON.stringify(data));
  },
  //数据管理患者基本信息数据 
  getDataUserInfo(data) {
    return api.get(`/bloodSugarPatientInfo/getDataUserBaseInfoById/id/${data.id}`);
  },
  //查询数据管理 折线图信息
  getLineChartInfo(data) {
    return api.get(`/bloodSugarPatientInfo/getDataUserLineChartInfo?id=${data.id}`);
  },
  /**
   * @条形码管理 
   */
  // // 查询所有条形码信息
  // getAllBarCode(data) {
  //   data.deanId = getdeanId();
  //   return api.get(`/bloodSugarEquipment/getAllBarcodeInfo?deanId=${data.deanId}`);
  // },
  /**
   * @出院患者
   */
  // 所有出院信息
  getAllOutInfo(data) {
    data.deanId = getdeanId();
    data.userId = getUserid();
    return api.post("/bloodSugarRole/getAllOutPatientInfo", JSON.stringify(data));
  },
  // pc删除质控批号信息
  deleteQualityControl(data) {
    return api.get(`/bloodSugarQualityControl/deleteQualityControl?qualityId=${data.qualityId}`);
  },
}
